﻿using System;
using System.Text;
using System.Threading;
using Mono.Collections.Generic;

namespace Mono.Cecil
{
	// Token: 0x020000BE RID: 190
	public sealed class PropertyDefinition : PropertyReference, IMemberDefinition, ICustomAttributeProvider, IMetadataTokenProvider, IConstantProvider
	{
		// Token: 0x17000215 RID: 533
		// (get) Token: 0x060007C9 RID: 1993 RVA: 0x000239A8 File Offset: 0x00021BA8
		// (set) Token: 0x060007CA RID: 1994 RVA: 0x00004D31 File Offset: 0x00002F31
		public PropertyAttributes Attributes
		{
			get
			{
				return (PropertyAttributes)this.attributes;
			}
			set
			{
				this.attributes = (ushort)value;
			}
		}

		// Token: 0x17000216 RID: 534
		// (get) Token: 0x060007CB RID: 1995 RVA: 0x000239C0 File Offset: 0x00021BC0
		// (set) Token: 0x060007CC RID: 1996 RVA: 0x00004D3B File Offset: 0x00002F3B
		public bool HasThis
		{
			get
			{
				bool flag = this.has_this != null;
				bool result;
				if (flag)
				{
					result = this.has_this.Value;
				}
				else
				{
					bool flag2 = this.GetMethod != null;
					if (flag2)
					{
						result = this.get_method.HasThis;
					}
					else
					{
						bool flag3 = this.SetMethod != null;
						result = (flag3 && this.set_method.HasThis);
					}
				}
				return result;
			}
			set
			{
				this.has_this = new bool?(value);
			}
		}

		// Token: 0x17000217 RID: 535
		// (get) Token: 0x060007CD RID: 1997 RVA: 0x00023A28 File Offset: 0x00021C28
		public bool HasCustomAttributes
		{
			get
			{
				bool flag = this.custom_attributes != null;
				bool result;
				if (flag)
				{
					result = (this.custom_attributes.Count > 0);
				}
				else
				{
					result = this.GetHasCustomAttributes(this.Module);
				}
				return result;
			}
		}

		// Token: 0x17000218 RID: 536
		// (get) Token: 0x060007CE RID: 1998 RVA: 0x00023A64 File Offset: 0x00021C64
		public Collection<CustomAttribute> CustomAttributes
		{
			get
			{
				return this.custom_attributes ?? this.GetCustomAttributes(ref this.custom_attributes, this.Module);
			}
		}

		// Token: 0x17000219 RID: 537
		// (get) Token: 0x060007CF RID: 1999 RVA: 0x00023A94 File Offset: 0x00021C94
		// (set) Token: 0x060007D0 RID: 2000 RVA: 0x00004D4A File Offset: 0x00002F4A
		public MethodDefinition GetMethod
		{
			get
			{
				bool flag = this.get_method != null;
				MethodDefinition result;
				if (flag)
				{
					result = this.get_method;
				}
				else
				{
					this.InitializeMethods();
					result = this.get_method;
				}
				return result;
			}
			set
			{
				this.get_method = value;
			}
		}

		// Token: 0x1700021A RID: 538
		// (get) Token: 0x060007D1 RID: 2001 RVA: 0x00023ACC File Offset: 0x00021CCC
		// (set) Token: 0x060007D2 RID: 2002 RVA: 0x00004D54 File Offset: 0x00002F54
		public MethodDefinition SetMethod
		{
			get
			{
				bool flag = this.set_method != null;
				MethodDefinition result;
				if (flag)
				{
					result = this.set_method;
				}
				else
				{
					this.InitializeMethods();
					result = this.set_method;
				}
				return result;
			}
			set
			{
				this.set_method = value;
			}
		}

		// Token: 0x1700021B RID: 539
		// (get) Token: 0x060007D3 RID: 2003 RVA: 0x00023B04 File Offset: 0x00021D04
		public bool HasOtherMethods
		{
			get
			{
				bool flag = this.other_methods != null;
				bool result;
				if (flag)
				{
					result = (this.other_methods.Count > 0);
				}
				else
				{
					this.InitializeMethods();
					result = !this.other_methods.IsNullOrEmpty<MethodDefinition>();
				}
				return result;
			}
		}

		// Token: 0x1700021C RID: 540
		// (get) Token: 0x060007D4 RID: 2004 RVA: 0x00023B4C File Offset: 0x00021D4C
		public Collection<MethodDefinition> OtherMethods
		{
			get
			{
				bool flag = this.other_methods != null;
				Collection<MethodDefinition> result;
				if (flag)
				{
					result = this.other_methods;
				}
				else
				{
					this.InitializeMethods();
					bool flag2 = this.other_methods != null;
					if (flag2)
					{
						result = this.other_methods;
					}
					else
					{
						Interlocked.CompareExchange<Collection<MethodDefinition>>(ref this.other_methods, new Collection<MethodDefinition>(), null);
						result = this.other_methods;
					}
				}
				return result;
			}
		}

		// Token: 0x1700021D RID: 541
		// (get) Token: 0x060007D5 RID: 2005 RVA: 0x00023BAC File Offset: 0x00021DAC
		public bool HasParameters
		{
			get
			{
				this.InitializeMethods();
				bool flag = this.get_method != null;
				bool result;
				if (flag)
				{
					result = this.get_method.HasParameters;
				}
				else
				{
					bool flag2 = this.set_method != null;
					result = (flag2 && this.set_method.HasParameters && this.set_method.Parameters.Count > 1);
				}
				return result;
			}
		}

		// Token: 0x1700021E RID: 542
		// (get) Token: 0x060007D6 RID: 2006 RVA: 0x00023C14 File Offset: 0x00021E14
		public override Collection<ParameterDefinition> Parameters
		{
			get
			{
				this.InitializeMethods();
				bool flag = this.get_method != null;
				Collection<ParameterDefinition> result;
				if (flag)
				{
					result = PropertyDefinition.MirrorParameters(this.get_method, 0);
				}
				else
				{
					bool flag2 = this.set_method != null;
					if (flag2)
					{
						result = PropertyDefinition.MirrorParameters(this.set_method, 1);
					}
					else
					{
						result = new Collection<ParameterDefinition>();
					}
				}
				return result;
			}
		}

		// Token: 0x060007D7 RID: 2007 RVA: 0x00023C6C File Offset: 0x00021E6C
		private static Collection<ParameterDefinition> MirrorParameters(MethodDefinition method, int bound)
		{
			Collection<ParameterDefinition> collection = new Collection<ParameterDefinition>();
			bool flag = !method.HasParameters;
			Collection<ParameterDefinition> result;
			if (flag)
			{
				result = collection;
			}
			else
			{
				Collection<ParameterDefinition> parameters = method.Parameters;
				int num = parameters.Count - bound;
				for (int i = 0; i < num; i++)
				{
					collection.Add(parameters[i]);
				}
				result = collection;
			}
			return result;
		}

		// Token: 0x1700021F RID: 543
		// (get) Token: 0x060007D8 RID: 2008 RVA: 0x00023CD0 File Offset: 0x00021ED0
		// (set) Token: 0x060007D9 RID: 2009 RVA: 0x00023D08 File Offset: 0x00021F08
		public bool HasConstant
		{
			get
			{
				this.ResolveConstant(ref this.constant, this.Module);
				return this.constant != Mixin.NoValue;
			}
			set
			{
				bool flag = !value;
				if (flag)
				{
					this.constant = Mixin.NoValue;
				}
			}
		}

		// Token: 0x17000220 RID: 544
		// (get) Token: 0x060007DA RID: 2010 RVA: 0x00023D2C File Offset: 0x00021F2C
		// (set) Token: 0x060007DB RID: 2011 RVA: 0x00004D5E File Offset: 0x00002F5E
		public object Constant
		{
			get
			{
				return this.HasConstant ? this.constant : null;
			}
			set
			{
				this.constant = value;
			}
		}

		// Token: 0x17000221 RID: 545
		// (get) Token: 0x060007DC RID: 2012 RVA: 0x00023D50 File Offset: 0x00021F50
		// (set) Token: 0x060007DD RID: 2013 RVA: 0x00004D68 File Offset: 0x00002F68
		public bool IsSpecialName
		{
			get
			{
				return this.attributes.GetAttributes(512);
			}
			set
			{
				this.attributes = this.attributes.SetAttributes(512, value);
			}
		}

		// Token: 0x17000222 RID: 546
		// (get) Token: 0x060007DE RID: 2014 RVA: 0x00023D74 File Offset: 0x00021F74
		// (set) Token: 0x060007DF RID: 2015 RVA: 0x00004D82 File Offset: 0x00002F82
		public bool IsRuntimeSpecialName
		{
			get
			{
				return this.attributes.GetAttributes(1024);
			}
			set
			{
				this.attributes = this.attributes.SetAttributes(1024, value);
			}
		}

		// Token: 0x17000223 RID: 547
		// (get) Token: 0x060007E0 RID: 2016 RVA: 0x00023D98 File Offset: 0x00021F98
		// (set) Token: 0x060007E1 RID: 2017 RVA: 0x00004D9C File Offset: 0x00002F9C
		public bool HasDefault
		{
			get
			{
				return this.attributes.GetAttributes(4096);
			}
			set
			{
				this.attributes = this.attributes.SetAttributes(4096, value);
			}
		}

		// Token: 0x17000224 RID: 548
		// (get) Token: 0x060007E2 RID: 2018 RVA: 0x0001B280 File Offset: 0x00019480
		// (set) Token: 0x060007E3 RID: 2019 RVA: 0x00003571 File Offset: 0x00001771
		public new TypeDefinition DeclaringType
		{
			get
			{
				return (TypeDefinition)base.DeclaringType;
			}
			set
			{
				base.DeclaringType = value;
			}
		}

		// Token: 0x17000225 RID: 549
		// (get) Token: 0x060007E4 RID: 2020 RVA: 0x0000A3A0 File Offset: 0x000085A0
		public override bool IsDefinition
		{
			get
			{
				return true;
			}
		}

		// Token: 0x17000226 RID: 550
		// (get) Token: 0x060007E5 RID: 2021 RVA: 0x00023DBC File Offset: 0x00021FBC
		public override string FullName
		{
			get
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append(base.PropertyType.ToString());
				stringBuilder.Append(' ');
				stringBuilder.Append(base.MemberFullName());
				stringBuilder.Append('(');
				bool hasParameters = this.HasParameters;
				if (hasParameters)
				{
					Collection<ParameterDefinition> parameters = this.Parameters;
					for (int i = 0; i < parameters.Count; i++)
					{
						bool flag = i > 0;
						if (flag)
						{
							stringBuilder.Append(',');
						}
						stringBuilder.Append(parameters[i].ParameterType.FullName);
					}
				}
				stringBuilder.Append(')');
				return stringBuilder.ToString();
			}
		}

		// Token: 0x060007E6 RID: 2022 RVA: 0x00004DB6 File Offset: 0x00002FB6
		public PropertyDefinition(string name, PropertyAttributes attributes, TypeReference propertyType) : base(name, propertyType)
		{
			this.attributes = (ushort)attributes;
			this.token = new MetadataToken(TokenType.Property);
		}

		// Token: 0x060007E7 RID: 2023 RVA: 0x00023E70 File Offset: 0x00022070
		private void InitializeMethods()
		{
			ModuleDefinition module = this.Module;
			bool flag = module == null;
			if (!flag)
			{
				object syncRoot = module.SyncRoot;
				lock (syncRoot)
				{
					bool flag3 = this.get_method != null || this.set_method != null;
					if (!flag3)
					{
						bool flag4 = !module.HasImage();
						if (!flag4)
						{
							module.Read<PropertyDefinition>(this, delegate(PropertyDefinition property, MetadataReader reader)
							{
								reader.ReadMethods(property);
							});
						}
					}
				}
			}
		}

		// Token: 0x060007E8 RID: 2024 RVA: 0x00023F14 File Offset: 0x00022114
		public override PropertyDefinition Resolve()
		{
			return this;
		}

		// Token: 0x040002AD RID: 685
		private bool? has_this;

		// Token: 0x040002AE RID: 686
		private ushort attributes;

		// Token: 0x040002AF RID: 687
		private Collection<CustomAttribute> custom_attributes;

		// Token: 0x040002B0 RID: 688
		internal MethodDefinition get_method;

		// Token: 0x040002B1 RID: 689
		internal MethodDefinition set_method;

		// Token: 0x040002B2 RID: 690
		internal Collection<MethodDefinition> other_methods;

		// Token: 0x040002B3 RID: 691
		private object constant = Mixin.NotResolved;
	}
}
